﻿using System.Collections.Generic;
using Wolfpack.Core.Testing;
using NUnit.Framework;
using Ploeh.AutoFixture;
using Wolfpack.Contrib.Publishers.Email;
using Wolfpack.Core.Interfaces.Entities;

namespace Wolfpack.Contrib.Tests.Publishers.Email
{
    /// <summary>
    /// Use smtp4Dev or another testing server to run unit tests
    /// </summary>
    [TestFixture]
    public class EmailPublisherTests
    {
        private Fixture _fixture;

        [SetUp]
        public void Setup()
        {
            _fixture = new Fixture();
            bool loaded = typeof(Microsoft.CSharp.RuntimeBinder.Binder).Assembly != null; //This is here just to get the RazorEngine initialized in the test
        }

        [Test]
        public void Publish_should_send_mail_successfully()
        {
            var config = new EmailConfiguration
            {
                Enabled = true,
                FriendlyId = "Email",
                FromAddress = "Wolfpack@Wolfpack.com",
                FromName = "Wolfpack Notifications",
                SmtpHost = "localhost",
                Port = 25,
                ToAddress = "notificationAddress@test.com",
                TemplatePath = "EmailPublisherTemplates",
                MailSubject = "Test Mail"
            };

            var publisher = new EmailPublisher(config);
            var notification = NotificationEventBuilder.From(new NotificationEventHealthCheck
                                                                 {
                                                                     DisplayUnit = "ms",
                                                                     Result = true,
                                                                     ResultCount = 555,
                                                                     CheckId = "Home Page UrlPing", 
                                                                     Message = "Some Info!",
                                                                     Tags = new List<string>()
                                                                 }).Build();
            publisher.Consume(notification);

            notification = NotificationEventBuilder.From(new NotificationEventHealthCheck
                                                                 {
                                                                     Result = false,
                                                                     CheckId = "Home Page UrlPing",
                                                                     Tags = new List<string> { "tag1", "tag2"}
                                                                 }).Build();
            publisher.Consume(notification);

            Assert.IsTrue(true); // As long as there is no exception, the integration test is ok
        }

    }
}
